package cn.com.bo.util.crypto;


import java.io.UnsupportedEncodingException;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EncodeUtil {
	
	private static Logger log = LoggerFactory.getLogger(EncodeUtil.class);
	
	private static String charset = "UTF-8";

	public static String encode(String url, String charset) {
		if (StringUtils.isNotBlank(url)) {
			try {
				return java.net.URLEncoder.encode(url, charset);
			} catch (Exception e) {
				log.error("EncodeUtil加密失败！错误信息{}", e.getMessage());
			}
		}
		return null;
	}
	
	public static String encode(String url){
		return encode(url, charset);
	}
	
	public static String decode(String url) {
		return decode(url, charset);
	}
	
	public static String decode(String url, String charset) {
		try {
			return java.net.URLDecoder.decode(url, charset);
		} catch (UnsupportedEncodingException e) {
			log.error("EncodeUtil解密失败！错误信息{}", e.getMessage());
		}
		return null;
	}
	
}
